package com.leoman.service.impl;

import com.leoman.core.Constant;
import com.leoman.entity.User;
import com.leoman.service.LoginService;
import com.leoman.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by wangbin on 2015/3/3.
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserService userService;

    // 总后台登陆
    @Override
    public Boolean login(HttpServletRequest request, String account, String password) {
        User user = userService.findOneByParams(account, password);
        if (null != user) {
            request.getSession().setAttribute(Constant.SESSION_MEMBER_GLOBLE, user);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void logOut(HttpServletRequest request, String type) {
        HttpSession session = request.getSession(false);
        if (Constant.MEMBER_TYPE_GLOBLE.equals(type)) {
            session.removeAttribute(Constant.SESSION_MEMBER_GLOBLE);
        }
    }
}
